/*********************************
*author:wuliangyu
*date  :2011-4-28
*e_mail:wuliangyue7@163.com
*/
#ifndef _KEYHOOK_H_
#define _KEYHOOK_H_
#define _CRT_SECURE_NO_DEPRECATE
#ifdef _MFC
    #include "stdafx.h"
#endif

#include <iostream>
#include <windows.h>
#include <map>
#include <vector>
#include <string>

using namespace std;

typedef unsigned int key;
typedef string kname;
typedef vector<string> mkey;
typedef void (*keyProc)(key);
typedef void (*mkeyProc)(void);
typedef map<key,key> keyMap;
typedef map<key,keyProc> keyFuncMap;
typedef map<vector<kname>, mkeyProc> mkeyFuncMap;

#ifdef _DEBUG
#define DMsg(text,cap) MessageBox( NULL, _T(text), cap, MB_OK ); 
#else 
#define DMsg(text,cap)
#endif

bool operator<(const vector<string>&lhs,const vector<string>&rhs);

class KeyHook
{
public:
    KeyHook();
	bool keyHookInit();
    bool keyInstead( key skey, key dkey );
    bool keyInstead( kname skeyname, kname dkeyname );
	bool keyFlollow( key fkey, key skey );
	bool keyFlollow( kname fkeyname, kname skeyname );
	bool keyEventDwn( key, keyProc );
	bool keyEventDwn( kname, keyProc );
	bool keyEventUp( key, keyProc );
	bool keyEventUp( kname, keyProc );
	bool mkeyEventAdd( mkey, mkeyProc );
	bool unHook();
	~KeyHook();

protected:
	static LRESULT CALLBACK keyHookProc( int ,WPARAM ,LPARAM );
	static kname GetKeyName( const key );
	static key   GetKeyCode( const kname );
	static bool DoHook(); 

private:
	static bool ChkMkey( mkey );
	
private:
	static keyMap key_instead;
	static keyMap key_follow;
	static keyFuncMap key_event_dwn;
	static keyFuncMap key_event_up;
	static mkeyFuncMap mkeyfuncmap;

public:
    static HHOOK khook;
private:
	//a flag to indecate the hook status
    static bool hookissetted;
};
#endif